Declaring variables in FBD

Use one of the following possibilities to declare one or more →variables within a →POU in →FBD:

In this article:
Good to know

(grey lightbulb) You are able to change some properties of an already declared variable later on. See under "Modifying variables" for the possibilities.

(grey lightbulb) If you require a →constant→retentive or →non-retentive variable, use the content assist. At present, Neuron Power Engineer supports only this possibility to declare such variables.

(grey lightbulb) The application navigator provides the possibility to declare external variables and to have the declarations based on the already existing global variables. This is done when you drag the global variables from a global-object onto a →POU. Details: See "Declaring external variables by dragging and dropping global variables into POUs".

(grey lightbulb)It is also possible to copy and paste variables and/or instances in order to declare new variables/instances based on already existing variables/instances.

Creating variables by using a dialog in the list of the declared variables

  1. Make the list of declared variables visible. 
    Alternative for an →input variable, →output variable or →in-/out variableOpen the interface editor for the object (from within the project explorer). 

  2. From the context menu, select New Variable... Alternative: Press the Ctrl-key and the +-key.

  3. In the dialog, enter the following properties for the variable and click OK.

    1. name – The name must be an →IEC-identifier
      (info)  If you want to declare several variables in one go, enter the name with , separating the names. Example: UpErr, QuitErr, MotorUp, MotorDown 

    2. section (= the variable section), e.g. LOCAL (for →local variable, also known as →internal variable), INPUT (for →input variable) etc.

      Restrictions

      →Temporary variables are not possible in FBD. →In-out variables cannot be declared in a →program, →global variables cannot be declared in a →function block or →function

  1. →data type or →function block type
    (warning) Multi-dimensional array data types are not supported for connecting to a block in-/output with a →generic data type (e.g. the in-/output of the MOVE block). 
    (info) Enter one or several letters so that a selection list with the corresponding data types and function blocks is provided.
    Subsequent changes to the selection are possible, e.g. by completing an →ARRAY declaration. For the STRING data type, STRING[80] is automatically entered. Overwrite 80, if you need a different length for the STRING variable.  

  2. →initial value (only optional required) – This initial value may be a →constant expression (in compliance with the →data type).
    It is not possible to assign an initial value to an →external variable 

Creating a Boolean local variable fast

  1. Make the list of declared variables visible. 

  2. From the context menu, select New Variable (LOCAL, BOOL). Alternative: Press Ctrl+Shift and the +-key.
    (info) If necessary, you are able to change the name as well as the data type later on. See under "Modifying variables".

Creating value fields with new variables

Use the command Variable(s) in the context menu of the drawing field to create one or more →value fields with the new variables. The necessary variables are automatically declared. 

  1. Position the mouse pointer over an empty space of the →graphical FBD-editor – where you need the value field.

  2. In the context menu of the FBD-editor, select Create and Variable(s). Alternative: Press Ctrl+Shift+V.

  3. In the dialog, enter the properties for the variable and click OK.
    This entry is analogous to the one described in "Creating variables by using a dialog in the list of the declared variables".

  4. Position the value field by pressing the primary mouse button or the Enter-key. The corresponding variables will be declared automatically, which makes them appear in the list of declared variables. This list is automatically displayed in this variant of creation.

Creating values fields with new variables (by using the content assist)

Use the content assist in order to create one or more value fields with the new variables. The necessary variables are automatically declared. 

  1. Position the mouse pointer over an empty space of the graphical FBD-editor – where you need the value field.

  2. Double-click or press Ctrl+Space.
    Result: An input field is opened.

  3. Declare the variables according to this syntax: X, Y : name_1, name_2, ..., name_n : type := initial-value (with the parts X, Y : and :=initial-value being optional).

  4. Press the Enter-key.
    Result: The preview of the value field is displayed.
    Result, if the variable already exists with a different data type: This conflict is reported. In this case, change the name of the variable to a unique name and press the Enter-key again.

  5. Position the value field by pressing the primary mouse button or the Enter-key.
    Result, if the variable has not been declared yet: The necessary variables are automatically declared. Hence, the variables are listed in the list of the declared variables.
    Result, if the variable already exists with a different section  X: This conflict is not reported. The existing variable of the different section is entered in the value field.

See "Creating value fields or calls of blocks by using the content assist in FBD", if you need more information on creating value fields.

Examples
  • var1, var2 : BOOL
    2 value fields will be created; one to contain an internal variable (due to the missing prefix for X)  named var1, the other to also contain an internal variable but named var2. Both variables are of →data type BOOL. There is no →initial value and no keyword (due to the missing prefix for Y).

  • I: var3 : INT := 5
    One value field will be created; It is to contain the input variable (due to I) named var3 of data type INT and the initial value 5.  There is no keyword (due to the missing prefix for Y).

  • C : var4 : INT := 5
    One value field will be created; It is to contain the internal variable (due to the missing prefix for X) named var4 of data type INT and the initial value 5.  Due to C, the variable is declared with the keyword CONSTANT, so it is a →constant internal variable.
    Note on a possible conflict: If there is already a variable named var4 of data type BOOL, this conflict is reported. The variable and the value field cannot be created.

  • L, C : var5 : BOOL
    One value field will be created; It is to contain the internal variable (due to L) named var5 of data type BOOL. There is no initial value. Due to C, the variable is also declared with the keyword CONSTANT.
    Note on a possible conflict: If there is already an external variable named var5 of data type BOOL, this conflict is not reported. Instead, the existing external variable is entered in the value field and the internal, constant variable var5 of data type BOOL is not declared.

  • I, R : var6 : INT
    One value field will be created; It is to contain the input variable (due to I) named var6 of data type INT. There is no initial value. Due to R, the variable is also declared with the keyword RETAIN, so it is a →retentive input variable.

  • O, NR : var7 : SINT
    One value field will be created; It is to contain the output variable (due to O) named var7 of data type SINT. There is no initial value. Due to NR, the variable is also declared with the keyword NON_RETAIN, so it is a non-retentive output variable.

Explanation of the syntax

Prefix "X"

Instead of X, enter the abbreviation for the required variable section:

  1. L for →local variables, also known as →internal variables (VAR)

  2. I for →input variables (VAR_INPUT)

  3. O for →output variables (VAR_OUTPUT)

  4. IO for →in-out variables (VAR_IN_OUT
    It is not possible to declare in-out variables in a →program.

  5. G for →global variables (VAR_GLOBAL
    It is not possible to declare global variables in a →function block or a →function.

  6. E for →external variables (VAR_EXTERNAL).
    It is only possible to declare an external variable in the function block or function, if there is already a global variable of the same name that has been declared in a →program or →resource (within a PLC-object). The declaration of an external variable in the program is only possible, if there is already a global variable of the same name that has been declared in a resource.
    Do you know the name of the global variable? If not, declare the external variable by using the next list of the content assist

    If you omit the abbreviation X, the variables are automatically created as local variables (VAR). See the previous examples. Restrictions for variable section see above.

 
Prefix "Y"

Instead of Y, enter the abbreviation for the required keyword:

  1. C for a →constant variable

  2. R for a →retentive variable

  3. NR for a →non-retentive variable

    If you omit the abbreviation Y (incl. , in front of it), the variables are automatically created without a keyword. See the previous examples.
    It is possible to combine the abbreviation C with the abbreviation R or NR. It is not possible to combine the abbreviations R and NR with each other. See the appropriate glossary articles, if you need information which keyword is possible for which variable section.
    It is also possible to enter the abbreviation for the keyword in front of the abbreviation for the variable section. Hence: Y, X :name_1, name_2, ..., name_n : type := initial-value

 
Name of variable

Instead of name_1, name_2, ..., name_n enter the names for the variables. The name must be an →IEC-identifier. If you want to declare just one variable, just enter one name (without ,).

 
Possible types

Instead of type, enter a data type or function block type. If necessary, you are able to change the type later on.

 
Initial value

Instead of initial-value, enter a initial value. This specification is optional. You are able to enter the initial value later on.